package com.example.blockingqueue.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.DelayQueue;
import java.util.concurrent.LinkedBlockingQueue;

@RestController
@RequestMapping("/blockingQueue")
public class BlockingQueueController {

    @Autowired
    private DelayQueue<Order> delayQueue;

    @Autowired
    @Qualifier("linkedQueue4Order")
    private LinkedBlockingQueue<Order> linkedQueue4Order;

    @Autowired
    @Qualifier("linkedQueue4Task")
    private LinkedBlockingQueue<Task> linkedQueue4Task;

    @GetMapping("/test")
    public String test() {
        return "success";
    }

    @GetMapping("/add")
    public String add() {
        Order order = new Order("1", 3000+System.currentTimeMillis());
        Order order1 = new Order("2", 5000 + System.currentTimeMillis());
        Order order2 = new Order("3", 1000 + System.currentTimeMillis());

        delayQueue.put(order);
        delayQueue.put(order1);
        delayQueue.put(order2);

        linkedQueue4Order.add(order);
        linkedQueue4Order.add(order1);
        linkedQueue4Order.add(order2);


        Task task1 = new Task("task-1", "task-1", "task-1", "task-1");
        Task task2 = new Task("task-2", "task-2", "task-2", "task-2");
        Task task3 = new Task("task-3", "task-3", "task-3", "task-3");

        linkedQueue4Task.add(task1);
        linkedQueue4Task.add(task2);
        linkedQueue4Task.add(task3);

        return "success";
    }




}
